
package com.shop.cloud.service.pay;

import java.util.Map;

import javax.annotation.Resource;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.config.AutowireCapableBeanFactory;
import org.springframework.stereotype.Service;

import com.google.common.collect.Maps;
import com.shop.cloud.common.PayResponse;
import com.shop.cloud.dao.pay.ApyAccountDao;
import com.shop.cloud.domain.pay.PayAccount;

@Service
public class ApyAccountService {

	@Autowired
    private ApyAccountDao apyAccountDao;

    @Resource
    private AutowireCapableBeanFactory spring;
    //缓存
    private final static Map<Long, PayResponse> payResponses = Maps.newConcurrentMap();

    /**
     *  获取支付响应
     */
    public PayResponse getPayResponse(Long id) {
        PayResponse payResponse = payResponses.get(id);
        if (payResponse  == null) {
            PayAccount apyAccount = apyAccountDao.get(id);
            if (apyAccount == null) {
                throw new IllegalArgumentException ("无法查询");
            }
            payResponse = new PayResponse();
            spring.autowireBean(payResponse);
            payResponse.init(apyAccount);
            payResponses.put(id, payResponse);
            // 查询
        }
        return payResponse;
    }


}
